package exam.xiecheng.autumn.S1;

import java.util.*;

public class Main {

    public static int n;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            long num = sc.nextLong();
            System.out.println(solution(num));
        }
    }

    private static long solution(long num) {
        String s = String.valueOf(num);
        char[] chars = s.toCharArray();
        int k = -1;
        for (int i=chars.length-1; i>=0; --i) {
            if ((chars[i] - '0') % 2 == 0) {
                k = i;
                break;
            }
        }
        if (k < 0)
            return -1;
        if (k == chars.length - 1)
            return num;
        char temp = chars[k];
        chars[k] = chars[chars.length-1];
        chars[chars.length-1] = temp;
        return Long.parseLong(String.valueOf(chars));
    }
}